package com.datou.utils;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.io.InputStream;

/**
 * 用于解析spring配置文件
 */

public class XMLUtils {
    public static String getBasePackage(String xmlFile) {
        SAXReader saxReader = new SAXReader();
        // 得到类的加载路径，获取spring配置文件
        InputStream inputStream = XMLUtils.class.getClassLoader().getResourceAsStream(xmlFile);

        try {
            Document document = saxReader.read(inputStream);
            Element rootElement = document.getRootElement();
            Element element = rootElement.element("component-scan");
            String basePackage = element.attribute("base-package").getText();
            return basePackage;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
